import O1HD from "../../engines/gameEngine";

const {ccclass, property} = cc._decorator;

@ccclass
export default class videoBtn extends cc.Component {

    iconSprite:cc.Sprite = null;

    static coinIcon:cc.SpriteFrame = null;

    static videoIcon:cc.SpriteFrame = null;

    onLoad(){
        this.loadSprite();
        this.iconSprite = this.node.getChildByName("icon").getComponent(cc.Sprite);
    }

    loadSprite(){
        if(!videoBtn.coinIcon){
            O1HD.getModules().uiControlModule.getFrameBundle().load(`public/image/mad`,cc.SpriteFrame,(err,spr:cc.SpriteFrame)=>{
                if(err){
                    console.log(err);
                    return;
                }
                videoBtn.coinIcon = spr;
            });
        }
        if(!videoBtn.coinIcon){
            O1HD.getModules().uiControlModule.getFrameBundle().load(`public/image/videoRed`,cc.SpriteFrame,(err,spr:cc.SpriteFrame)=>{
                if(err){
                    console.log(err);
                    return;
                }
                videoBtn.videoIcon = spr;
            });
        }
    }
    
    update(dt: number){
        let coin = O1HD.getServices().userSrv.getCoins();
        this.iconSprite.spriteFrame = coin > 0 ? videoBtn.coinIcon : videoBtn.videoIcon;
    }

}
